package com.qf.smsplatform.strategy.util;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.constants.ReportStateConstants;
import com.qf.smsplatform.common.model.StandardReport;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.common.util.SpringUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * 策略模块校验未通过时，发送消息的工具类
 * @author zjw
 */
public class PushErrorMessageUtil {


    /**
     * 发送消息到下发日志队列
     */
    public static void sendLog(StandardSubmit submit,String errorCode){
        submit.setErrorCode(errorCode);
        submit.setReportState(ReportStateConstants.FAIL);
        // 从Spring容器中获取实例
        RabbitTemplate rabbitTemplate = SpringUtil.getBean(RabbitTemplate.class);
        rabbitTemplate.convertAndSend(RabbitMQConstants.TOPIC_SMS_SEND_LOG,submit);
    }

    /**
     * 发送消息到状态报告队列
     */
    public static void sendReport(StandardSubmit submit,String errorCode){
        //1. 将Report对象封装出来
        StandardReport report = new StandardReport();
        report.setSequenceId(submit.getSequenceId());
        report.setClientID(submit.getClientID());
        report.setMobile(submit.getDestMobile());
        report.setSrcID(submit.getSrcSequenceId());
        report.setErrorCode(errorCode);
        report.setState(ReportStateConstants.FAIL);
        // 2. 发送消息
        // 从Spring容器中获取实例
        RabbitTemplate rabbitTemplate = SpringUtil.getBean(RabbitTemplate.class);
        rabbitTemplate.convertAndSend(RabbitMQConstants.TOPIC_PUSH_SMS_REPORT,report);
    }

}
